//
//  BangBankWebviewViewController.m
//  customer
//
//  Created by 往返网络 on 17/8/26.
//  Copyright © 2017年 com. All rights reserved.
//

#import "BangBankWebviewViewController.h" //绑定银行卡h5界面

@interface BangBankWebviewViewController ()<UIWebViewDelegate,UIScrollViewDelegate>
//@property (nonatomic) JSContext *jsContext;
@end

@implementation BangBankWebviewViewController
{
    UIWebView * _webView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
    // Do any additional setup after loading the view.
}

- (void)createUI{

    self.view.backgroundColor = [UIColor whiteColor];
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, SCREEN_W, SCREEN_H)];
    _webView.delegate = self;
    _webView.scalesPageToFit = YES;
    _webView.scrollView.delegate =self;
    _webView.userInteractionEnabled = YES;
    NSString * url  = [NSString stringWithFormat:@"https://my-uat1.orangebank.com.cn/khpayment/UnionAPI_Open.do&orig=%@&sign=%@&returnurl=http://118.190.70.13/Appcustomernewer/PayNotifyUrl/payAddMyCardBack&NOTIFYURL=http://118.190.70.13/Appcustomernewer/PayNotifyUrl/payAddMyCardBackNoUse",self.orig,self.sign];
    NSLog(@"获取h5 url %@",url);
    NSMutableURLRequest *request =[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
    [request setHTTPMethod: @"POST"];
    [request setHTTPBody: [url dataUsingEncoding: NSUTF8StringEncoding]];
    [_webView loadRequest:request];
    [self.view addSubview:_webView];

}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//    _jsContext = [webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
//    _jsContext[@"startFunction"] = ^(id obj){
//        //这里通过block回调从而获得h5传来的json数据
//        /*block中捕获JSContexts
//         我们知道block会默认强引用它所捕获的对象，如下代码所示，如果block中直接使用context也会造成循环引用，这使用我们最好采用[JSContext currentContext]来获取当前的JSContext:
//         */
//        [JSContext currentContext];
//        
//        NSLog(@"啦啦啦啦");
//        
//        
//    };
//    _jsContext.exceptionHandler = ^(JSContext *context, JSValue *exceptionValue){
//        context.exception = exceptionValue;
//        NSLog(@"异常信息：%@",exceptionValue);
//    };
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
